package com.lanren.familybookapp.ui.me.presenter;

import com.lanren.common.base.impl.BasePresenter;
import com.lanren.easyhttp.body.UIProgressResponseCallBack;
import com.lanren.easyhttp.subsciber.IProgressDialog;
import com.lanren.familybookapp.ui.me.interfaces.IOneselfModel;
import com.lanren.familybookapp.ui.me.model.OneselfModel;

/**
 * @ClassName OneselfPresenter
 * @Description TODO
 * @Author chongheng.wang
 * @Date 2019/10/11 14:20
 * @Version 1.0
 */
public class OneselfPresenter extends BasePresenter<IOneselfModel.IOneselfView> {
    private OneselfModel oneselfModel;

    public OneselfPresenter() {
        oneselfModel = new OneselfModel();
    }


    public void updateFile(String path, IProgressDialog mProgressDialog, UIProgressResponseCallBack listener) {
        oneselfModel.updateAvatar(path, mProgressDialog, listener);
    }

    public void updateUserInfo(String name, String sex, String age) {
        mRootView.showLoading();
        oneselfModel.updateUserInfo(name, sex, age, new IOneselfModel.OneselfModel() {
            @Override
            public void onError(int code, String data) {
                mRootView.showComplete();
                mRootView.showError(code, data);
            }

            @Override
            public void onSuccess() {
                mRootView.showComplete();
                mRootView.onSuccess();
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (oneselfModel != null) {
            oneselfModel.clearDisposable();
            oneselfModel = null;
        }
    }
}
